package com.ww.boot.字节码2;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;


/**
 * 生成jar包前 直接修改class文件
 */
public class Generator {
    public static void main(String[] args) throws Exception {
        //FileInputStream fis = new FileInputStream("");
                //读取
        ClassReader classReader = new ClassReader("com\\ww\\boot\\字节码2\\Base");
        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        //处理
        ClassVisitor classVisitor = new MyClassVisitor(classWriter);
        classReader.accept(classVisitor, ClassReader.SKIP_DEBUG);
        byte[] data = classWriter.toByteArray();
        String str = new String(data);
        System.out.println(str);
        //输出
        File f = new File("boot-tools/boot-bytecode/target/classes/com/ww/boot/字节码2/Base1.class");
        FileOutputStream fout = new FileOutputStream(f);
        fout.write(data);
        fout.close();
        System.out.println("now generator cc success!!!!!");
    }
}